package com.example.springbootrbac.controller;

import com.example.springbootrbac.entity.AnnouncementEntity;
import com.example.springbootrbac.entity.BuildingEntity;
import com.example.springbootrbac.entity.MessagesBoardEntity;
import com.example.springbootrbac.entity.RoomEntity;
import com.example.springbootrbac.pojo.Result;
import com.example.springbootrbac.pojo.ResultCode;
import com.example.springbootrbac.service.DeleteService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class DeleteController {
    @Resource(name="deleteServiceImpl")
    DeleteService deleteService;
    @PostMapping("/index/announcement/delete")
    public Result<String> deleteAnnouncement(Long id,HttpServletRequest request ){
        System.out.println("前端参数:id"+id);
        if(ObjectUtils.isEmpty(id)){
            return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"想要删除的数据不存在");
        }
        String token = deleteService.deleteAnnouncement(id,request);
        if(!ObjectUtils.isEmpty(token)){
            return Result.success("删除成功");
        }
        return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"只有管理员才能删除哦");
    }

    @PostMapping("/index/homework/delete")
    public Result<String> deleteRoom(Long id ,HttpServletRequest request ){
        System.out.println("前端参数:id"+id);
        if(ObjectUtils.isEmpty(id)){
            return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"想要删除的数据不存在");
        }
        String token = deleteService.deleteRoom(id,request);
        if(!ObjectUtils.isEmpty(token)){
            return Result.success("删除成功");
        }
        return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"不能删除其他人的信息哦");
    }

    @PostMapping("/index/course/delete")
    public Result<String> deleteCourse(Long id,HttpServletRequest request ){
        System.out.println("前端参数:id"+id);
        if(ObjectUtils.isEmpty(id)){
            return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"想要删除的数据不存在");
        }
        String token = deleteService.deleteCourse(id,request);
        if(!ObjectUtils.isEmpty(token)){
            return Result.success("删除成功");
        }
        return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"您无权进行此操作");
    }

    @PostMapping("/index/messageBoards/delete")
    public Result<String> deleteMessageBoard(Long id ,HttpServletRequest request ){
        System.out.println("前端参数:id="+id);
        if(ObjectUtils.isEmpty(id)){
            return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"想要删除的数据不存在");
        }
        String token = deleteService.deleteMessageBoard(id,request);
        if(!ObjectUtils.isEmpty(token)){
            return Result.success("删除成功");
        }
        return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"不能删除其他人的留言哦");
    }
    @PostMapping("/index/member/delete")
    public Result<String> deleteUser(Long id ,HttpServletRequest request ){
        System.out.println("前端参数:id="+id);
        if(ObjectUtils.isEmpty(id)){
            return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"想要删除的数据不存在");
        }
        String token = deleteService.deleteUser(id,request);
        if(!ObjectUtils.isEmpty(token)){
            return Result.success("删除成功");
        }
        return Result.failure(ResultCode.FAILURE_DELETE_ERROR,"只有管理员才能执行哦");
    }
}
